If you compile with warnings, you should see something like the following:
Code:
/*
main.c||In function 'main':|
main.c|21|warning: statement with no effect|
||=== Build finished: 0 errors, 1 warnings ===|
*/
This is because you accidentally used == (comparison) instead of = (assignment).
In fact, as you fix up the code, you'll see the "if(modulo==0)" code isn't even necessary.
The reason you're seeing gibberish sometimes is because you break out of the loop when the number goes below 1, but all the array positions have not necessarily been filled yet. Therefore, when you attempt to print out the numbers at those indices, since they have not been initialized to anything, they contain garbage values.
Try initializing the entire array to zero. This way, anything not updated in the loop will still have an initial value.
Code:
int BitNum[8] = {0}; // initialize all elements to zero
Then, as mentioned, you want to reverse the array so it prints the bits in the correct order.
I am happy to see several things about your code. Neat/consistent indentation, meaningful variable names, proper form of "main()". We don't get enough of that here from new posters. Well done!